import java.io.Serializable;

public class Schedule implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id; // 场次ID
    private String movieId; // 关联的影片ID
    private String hall; // 放映厅
    private String date; // 日期
    private String time; // 时间
    private boolean[] seats; // 座位状态，true=已售，false=可售

    public Schedule(String id, String movieId, String hall, String date, String time, int seatCount) {
        this.id = id;
        this.movieId = movieId;
        this.hall = hall;
        this.date = date;
        this.time = time;
        this.seats = new boolean[seatCount]; // 初始化座位，默认都是可售
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMovieId() {
        return movieId;
    }

    public void setMovieId(String movieId) {
        this.movieId = movieId;
    }

    public String getHall() {
        return hall;
    }

    public void setHall(String hall) {
        this.hall = hall;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public boolean[] getSeats() {
        return seats;
    }

    public boolean isSeatSold(int index) {
        if (index >= 0 && index < seats.length) {
            return seats[index];
        }
        return false;
    }

    public boolean sellSeat(int index) {
        if (index >= 0 && index < seats.length && !seats[index]) {
            seats[index] = true;
            return true;
        }
        return false;
    }

    public boolean refundSeat(int index) {
        if (index >= 0 && index < seats.length && seats[index]) {
            seats[index] = false;
            return true;
        }
        return false;
    }

    public int getAvailableSeatsCount() {
        int count = 0;
        for (boolean seat : seats) {
            if (!seat) count++;
        }
        return count;
    }
}
